<template>
    <view>
        <view class="form_list_bg">
            <text class="form_list_title">发圈</text>
            <image  style="width: 100%;height: 167rpx;" src="https://image1.sansancloud.com/linwenlaoshi/2020_9/9/17/42/39_192.jpg"></image>
        </view>
        <view class="form_list_container">
            <form-commit-list-component id="formCommitList" showBtn="ture" :receiveData="sendOptionData" v-if="sendOptionData" @returnFormNameFun="getDataFun"></form-commit-list-component>
        </view>
       <custom-page-index-component id="container" @refreshFun="getRefreshFun"></custom-page-index-component>
    </view>
</template>

<script>
import publicFun from '../../wxcomponents/public/publicFun.wxs'

export default {
  data() {
    return {
      formData: {},
      moneyAmount: 0,
      mendian: null,
      loading: true,
      publishState: false,
      customFormId: 0,
      showCount: false,
      formType: [],
      showTop: false,
      sendOptionData: null,
      statusBarHeight:getApp().globalData.statusBarHeight,
      /**
       * 生命周期函数--监听页面加载
       */
      params: {},
      listPage: {
        page: 1,
        pageSize: 20,
        totalSize: 0,
        customFormId: ""
      },
      formCommitList: "",
      selectTab: [],
      selectTabIndex: "",
      setting: ""
    };
  },
  props: {},
  onLoad: function (options) {
    this.publicFun = publicFun;
    let that = this;
    that.initSetting();
    console.log('===options===', options);
    that.setData({
      sendOptionData: options
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.reflesh == 1) {
      this.onPullDownRefresh();
    }
    getApp().globalData.addAuthorizationListenerItem(this)//授权头像
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let that = this;
    that.Data = [];
    let sendOptionData = that.sendOptionData;
    console.log("========onPullDownRefresh============", that.selectResultsObj);
    that.selectComponent("#formCommitList").pullDownRefreshFun();
    wx.hideNavigationBarLoading(); //完成停止加载

    wx.stopPullDownRefresh(); //停止下拉刷新
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('===onReachBottom====');
    let that = this;
    that.selectComponent("#formCommitList").reachBottomFun(); // if (that.listPage.totalSize > that.listPage.page * that.listPage.pageSize) {
    //   that.listPage.page++
    //   this.getData();
    // }
  },

  /**
     * 用户点击右上角分享
     */
  onShareTimeline:function(){
    return this.shareFun();
  },
  onShareAppMessage: function (res) {
    console.log(res);
    return this.shareFun();
  },
  methods: {
    getStateData: function (state) {
      let that = this;
      console.log("===getStateData===", state);
      that.selectComponent("#container").setPopupState(state);
    },
    getRefreshFun:function(){
        let that=this;
        // that.linkEvent(that.backUrl,'reLaunch');
    },
    shareFun:function(){
        let that = this;
        that.closeZhezhao();
        let customFormData = that.selectComponent("#formCommitList").data.customFormData;
        console.log('that.data.customFormData:', customFormData);
        let params = {
          customFormId: customFormData.id
        };
        let shareName = customFormData.name;
        console.log('params:', params);
        return getApp().globalData.shareForFx2('form_commit_list', shareName, params, '', 'customFormId');
    },
    getDataFun: function (e) {
      let that = this;
      console.log("===getDataFun===", e);
      let data = e.detail;
      // wx.setNavigationBarTitle({
      //   title: data.formName
      // });
    },
    showMore: function (e) {
      console.log("==showMore===", e);
      let that = this;
      let type = e.currentTarget.dataset.type;
      let index = e.currentTarget.dataset.index;
      let length = e.currentTarget.dataset.length || 2;
      let state = type == "show" ? true : false;
      let showNum = type == "show" ? length : 2;
      that.formCommitList[index].showMoreState = state;
      that.formCommitList[index].showNum = showNum;
      that.setData({
        formCommitList: that.formCommitList
      });
    },

    /* 组件事件集合 */
    tolinkUrl: function (data) {
      let linkUrl = data.currentTarget ? data.currentTarget.dataset.link : data;
      console.log("==linkUrl===", linkUrl);
      getApp().globalData.linkEvent(linkUrl);
    },
    getFormDetail: function (customFormId) {
      let that = this;
      let formDetailData = getApp().globalData.AddClientUrl("/wx_get_custom_form.html", {
        customFormId: customFormId || ""
      }, 'get');
      console.log('==formDetailData===', formDetailData);
      wx.request({
        url: formDetailData.url,
        data: formDetailData.params,
        header: getApp().globalData.headerPost,
        method: 'get',
        success: function (res) {
          console.log(res);

          if (res.data.errcode == 0) {
            let data = res.data.relateObj;
            that.setData({
              formData: data
            });
          } else {
            that.setData({
              selectTab: []
            });
          }
        }
      });
    },
    closeZhezhao: function () {
      let that = this;
      let selectTab = that.selectTab;
      that.setData({
        showCount: false
      });
      that.setData({
        selectTabIndex: -1
      });

      for (let i = 0; i < selectTab.length; i++) {
        selectTab[i].state = false;
      }

      that.setData({
        selectTab: selectTab
      });
    },

    initSetting() {
      this.setData({
        setting: getApp().globalData.setting
      });
    },

    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style scoped>
@import "./index.css";
</style>